<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE head PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@ include file="/static/include/common.inc"%>
<link rel="stylesheet" href="static/admin/css/layui.css">
<link rel="stylesheet" href="static/admin/css/main.css" media="all">
<link rel="stylesheet" href="static/layui_v2.2.3/css/zbyui.css">
<script src="static/js/jquery-1.11.2.js"></script>
<script src="static/layui_v2.2.3/layui.js"></script>
</head>
<body>
	<form class="layui-form" action="">
		<input type="hidden" name="userId" value="${user.userId }" id="userId">
		<div class="layui-form-item">
			<label class="layui-form-label">用户名</label>
			<div class="layui-input-block">
				<input type="text" name="userName" required lay-verify="required"
					placeholder="请输入用户名" autocomplete="off" class="layui-input" value="${user.userName }">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">密码</label>
			<div class="layui-input-block">
				<input type="text" name="password" required lay-verify="required"
					placeholder="请输入密码" autocomplete="off" class="layui-input" value="" maxlength="32">
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-input-block" style="align-items: center;">
				<button class="layui-btn" lay-submit lay-filter="formDemo">保存</button>
				<button class="layui-btn layui-btn-primary" id="zby-closeBtn">关闭</button>
			</div>
		</div>
	</form>
	<script type="text/javascript">
		layui.use([ 'form', 'laydate' ], function() {
			var form = layui.form;
			var laydate = layui.laydate;
			//执行一个laydate实例
			laydate.render({
				elem : '#releaseTimeStr' //指定元素
			});
			//监听提交
			form.on('submit(formDemo)', function(data) {
				$(".layui-btn[lay-filter='formDemo']").addClass("layui-btn-disabled");
				$.ajax({
					type : "post",
					url : "admin/user/updateUser.do",
					data : data.field,
					async: false,
					success : function(result) {
						if (result.code == 0) {
							parent.layer.msg(result.msg);
							setTimeout(closeOpt,1500);
						} else {
							parent.layer.msg(result.msg);
						}
					}
				});
				return false;
			});
		});
		function closeOpt(){
			var index=parent.layer.getFrameIndex(window.name);
			//parent.layer.close(index);
			//window.parent.location.reload();
			
			window.parent.location.href="admin.do"
		}
		$("#zby-closeBtn").bind("click",function(){
			var index=parent.layer.getFrameIndex(window.name);
			parent.layer.close(index);
		})
		$("#zby-img").bind("click", function() {
			$("#zby-upload").click();
		})
		var formData;
		$("#zby-upload").bind("change", function() {
			formData = new FormData();
			console.log(this.files[0])
			for(var i=0;i<this.files.length;i++){
				formData.append("files"+i,this.files[i]);
			}
			// 创建 一个FileReader对象
    		var reader = new FileReader();
    		// 读取文件作为URL可访问地址
    		reader.readAsDataURL(this.files[0]);
    		reader.onload=function(e){
				$("#zby-img").attr("src",e.target.result)
				//$("#zby-upload").val(e.target.result)
    		}
    		console.log(formData);
    		//return false;
    		$.ajax({
				type : "post",
				url : "front/image/manyFileUpload.do",
				data : formData,
				async: false,
				processData: false,  // 告诉jQuery不要去处理发送的数据
	            contentType: false,   // 告诉jQuery不要去设置Content-Type请求头
				success : function(result) {
					if (result.code == 1) {
						$("#logoUrl").val(result.path)
					} else {
						//layer.msg(result.msg);
					}
				}
			}); 
		})
	</script>
</body>
</html>